use crate::message;

pub fn parse_header(header:[u8;8]) -> (u32, u32) {
    ((header[0] as u32) << 24 | (header[1] as u32) << 16 | (header[2] as u32) << 8 | header[3] as u32, (header[4] as u32) << 24 | (header[5] as u32) << 16 | (header[6] as u32) << 8 | (header[7] as u32))
}

pub fn serialize_header(id:u32,len:u32) -> [u8;8] {
    [(id >> 24) as u8, (id >> 16) as u8, (id >> 8) as u8, id as u8, (len >> 24) as u8, (len >> 16) as u8, (len >> 8) as u8, len as u8]
}

pub fn serialize_vec_header(id:u32,len:u32) -> Vec<u8> {
    vec![(id >> 24) as u8, (id >> 16) as u8, (id >> 8) as u8, id as u8, (len >> 24) as u8, (len >> 16) as u8, (len >> 8) as u8, len as u8]
}

pub fn pack(mut msg:message::Message) -> Vec<u8> {
    let mut header = serialize_vec_header(msg.id, msg.len);
    header.append(&mut msg.data);
    header
}